package GUImk2;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MainPanel extends JPanel {

	/**
	 * Allows serialization.
	 */
	private static final long serialVersionUID = -5463654206148823511L;
	
	/**
	 * Burning penguins icon.
	 */
	private BufferedImage image;
	
	/**
	 * The parent frame for this panel.
	 */
	private FullFrame my_frame;
	
	/**
	 * Layout for flipping panels.
	 */
	private CardLayout my_layout;
	
	/**
	 * The string labels for the different content panels that will be available.
	 */
	protected static final String[] LAYOUT_LABELS = {		//default -- logout
		"default", "login", "submitAuth", "submitRev", 		// 0 1 2 3
		"submitRecc", "review", "edit", "assign", 			// 4 5 6 7
		"accept", "designate", "status", "viewAssign",		// 8 9 10 11
		"author", "reviewer", "subprog", "chair"			// 12 13 14 15 
	};
	
	/**
	 * Constructor for building the parent panel.
	 * 
	 * @param the_frame the frame that the panel is attached to.
	 */
	public MainPanel(FullFrame the_frame) {
		super();
		my_frame = the_frame;
		my_layout = new CardLayout(0, 0);
		this.setLayout(my_layout);
		this.add(logoPanel(), LAYOUT_LABELS[0]);
		this.add(loginPanel(), LAYOUT_LABELS[1]);
		this.add(submitAuthPanel(), LAYOUT_LABELS[2]);
		this.add(submitRevPanel(), LAYOUT_LABELS[3]);
		this.add(submitReccPanel(), LAYOUT_LABELS[4]);
		this.add(getReviewPanel(), LAYOUT_LABELS[5]);
		this.add(editPanel(), LAYOUT_LABELS[6]);
		this.add(assignPanel(), LAYOUT_LABELS[7]);
		this.add(acceptPanel(), LAYOUT_LABELS[8]);
		this.add(designatePanel(), LAYOUT_LABELS[9]);
		this.add(statusPanel(), LAYOUT_LABELS[10]);
		this.add(viewAssign(), LAYOUT_LABELS[11]);
		this.add(authorPanel(), LAYOUT_LABELS[12]);
		this.add(reviewPanel(), LAYOUT_LABELS[13]);
		this.add(subprogPanel(), LAYOUT_LABELS[14]);
		this.add(chairPanel(), LAYOUT_LABELS[15]);
		
		this.setVisible(true);		
	}

	/**
	 * Method for switching visible panels.  Use the LAYOUT_LABELS array
	 * for valid arguments.
	 * 
	 * @param newPanel
	 */
	protected void updateMainPanel(final String newPanel) {
		my_layout.show(this, newPanel);
	}
	
	/**
	 * Default panel.
	 * 
	 * @return panel with burning penguin on it.
	 */
	private JPanel logoPanel() {
		JPanel design = factoryPanel();
		try {
			// this is mainly for comic relief.  If we do get an actual icon for this, replace reference here.
			image = ImageIO.read(new File("setFire.jpg"));
			JLabel bpIcon = new JLabel(new ImageIcon(image));
			design.setLayout(new BorderLayout());
			design.add(bpIcon);
		} catch (IOException e) {
			
		}
		design.setVisible(true);
		return design;
	}

	
	private JPanel chairPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("You are logged in as Program Chair"));
		return panel;
	}

	private JPanel subprogPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("You are logged in as Subprogram Chair"));
		return panel;
	}

	private JPanel reviewPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("You are logged in as Reviewer"));
		return panel;
	}

	private JPanel authorPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("You are logged in as Author"));
		return panel;
	}

	private JPanel viewAssign() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("The current assignments for this conference are:"));
		return panel;
	}


	private JPanel statusPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("Listing of papers and their status:"));
		return panel;
	}


	private JPanel designatePanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("Designate Subprogram Chair for Manuscript:"));
		return panel;
	}


	private JPanel acceptPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("Accept which manuscript?"));
		return panel;
	}


	private JPanel assignPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("Assign what paper to which reviewer?"));
		return panel;
	}


	private JPanel editPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("Edit (or remove) which submission?"));
		return panel;
	}


	private JPanel getReviewPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("You have the following reviews:"));
		return panel;
	}


	private JPanel submitReccPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("Select a recommendation for each of the following manuscripts:"));
		// TODO list manuscripts and have some form of radiobutton selection or drop-down menu selection.
		return panel;
	}


	private JPanel submitRevPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("Submit a review for which manuscript?"));
		return panel;
	}


	private JPanel submitAuthPanel() {
		JPanel panel = factoryPanel();
		panel.add(new JLabel("Submit which document for this conference?"));
		return panel;
	}
	
	/**
	 * Creates the login panel.
	 * 
	 * For Testing will just have a series of buttons to allow role switching.
	 * 
	 * @return the panel displayed when login is occurring.
	 */
	private JPanel loginPanel() {
		JPanel design = factoryPanel();
		
		design.setLayout(new BoxLayout(design, BoxLayout.Y_AXIS));
		
		JLabel loginPrompt = new JLabel("Welcome to the Conference Manager.  Please select a role to log in as:");
		loginPrompt.setAlignmentX(CENTER_ALIGNMENT);
		design.add(loginPrompt);
		design.add(Box.createVerticalStrut(45));
		
		Button2 author = new Button2("Author");
		author.setPattern(MainPanel.LAYOUT_LABELS[12], my_frame);
		author.setAlignmentX(CENTER_ALIGNMENT);
		design.add(author);
		design.add(Box.createVerticalStrut(30));
		
		Button2 review = new Button2("Reviewer");
		review.setPattern(MainPanel.LAYOUT_LABELS[13], my_frame);
		review.setAlignmentX(CENTER_ALIGNMENT);
		design.add(review);
		design.add(Box.createVerticalStrut(30));
		
		Button2 subprog = new Button2("SubProgram Chair");
		subprog.setPattern(MainPanel.LAYOUT_LABELS[14], my_frame);
		subprog.setAlignmentX(CENTER_ALIGNMENT);
		design.add(subprog);
		design.add(Box.createVerticalStrut(30));
		
		Button2 chair = new Button2("Program Chair");
		chair.setPattern(MainPanel.LAYOUT_LABELS[15], my_frame);
		chair.setAlignmentX(CENTER_ALIGNMENT);
		design.add(chair);
		
		return design;
	}
	
	/**
	 * Helper method for creating panels to set defaults.
	 * 
	 * @return created panel.
	 */
	private JPanel factoryPanel() {
		JPanel panel = new JPanel();
		//panel.setBackground(Color.LIGHT_GRAY);
		panel.setPreferredSize(new Dimension(650, 600));
		return panel;
	}

}
